package com.example.administrator.xxnapp.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.xxnapp.R;


/**
 * Created by Went_Gone on 2018/1/15.
 */
public class ItemTextRawLayout extends RelativeLayout {
    private TextView mTVtitle;
    private String title;
    private int iconLeft;
    private ImageView mIV;

    public ItemTextRawLayout(Context context) {
        this(context,null);
    }

    public ItemTextRawLayout(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ItemTextRawLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View.inflate(context, R.layout.layout_item_text,this);

        mTVtitle = findViewById(R.id.layout_item_text_TV);
        mIV = findViewById(R.id.layout_item_text_IV);

        initAttrs(context,attrs);

        if (title == null){
            title = "";
        }
        mTVtitle.setText(title);
        mTVtitle.setTextColor(Color.parseColor("#333333"));

        if (iconLeft == R.mipmap.ic_launcher){
            mIV.setVisibility(GONE);
        }else {
            mIV.setVisibility(VISIBLE);
            mIV.setImageResource(iconLeft);
        }
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray array = context.obtainStyledAttributes(attrs,R.styleable.ItemTextRawLayout);
        title = array.getString(R.styleable.ItemTextRawLayout_title);
        iconLeft = array.getResourceId(R.styleable.ItemTextRawLayout_leftIcon,R.mipmap.ic_launcher);
        array.recycle();
    }
}
